<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/3/30
 * Time: 15:21
 */

namespace common\models\datas;


use common\components\bases\BaseModel;
use common\components\extenders\MenuManage;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\helpers\ArrayHelper;

class Customercategory extends BaseModel
{
    public static function tableName(){
        return '{{%customer_category}}';
    }

    public function rules(){
        return [
            [['name'], 'required'],
            [['created_at', 'updated_at'], 'integer'],
        ];
    }

    public function fields(){
        $fields = parent::fields();
        $fields['created_at'] = function(){
            return \Yii::$app->formatter->asDatetime($this->created_at);
        };
        $fields['updated_at'] = function(){
            return \Yii::$app->formatter->asDatetime($this->updated_at);
        };
        $fields['updated_at'] = function(){
            return \Yii::$app->formatter->asDatetime($this->updated_at);
        };
        return $fields;
    }

    /**public function extraFields(){
        return [
            'backend_operate' => function(){
                return (new MenuManage(MenuManage::RECORD_ITEM_TOOLBAR,$this->attributes))->create();
            }
        ];
    }*/

    public function attributeLabels(){
        return [
            'id' => \Yii::t('common','自动编号'),
            'name' => \Yii::t('common','会员分类名'),
        ];
    }

    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            [
                'class' => TimestampBehavior::className(),
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
                    ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
                ],
            ],
        ]);
    }
}